package com.venus.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.venus.entity.Menu;
import com.venus.entity.Page;
import com.venus.mapper.MenuMapper;
import com.venus.service.MenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * Created by admin on 28/6/17.
 */
@Service
public class MenuServiceImpl implements MenuService {

	@Resource
	private MenuMapper menuMapper;

	@Override
	public List<Menu> getAllParentNodeInfo() {

		return menuMapper.getAllParentNodeInfo();
	}

	@Override
	public void addMenu(Menu menu) {
		menuMapper.addMenu(menu);
	}

	@Override
	public Menu findMenuInfoById(int id) {
		return menuMapper.findMenuInfoById(id);
	}

	@Override
	public List<LinkedHashMap<String, String>> findAllMenus() {
		return menuMapper.findAllMenus();
	}

	@Override
	public PageInfo<Menu> findMenusByPageList(Page page) {
		PageHelper.startPage(page.getCurrentPage(), page.getSize());
		List<Menu> list = menuMapper.findMenus((Menu)page.getObject());
		return new PageInfo<Menu>(list);
	}

	@Override
	public void updateMenu(Menu menu) {
		menuMapper.updateMenu(menu);
	}
}
